Preamble

Column {data-width 400}

Flexdashboard Template for DSI AT2

I’m not sure a flexdashboard is a great way to present this kind of work, because it’s a lot of text, while dashboards are really built for bits of commentary but mostly visual information.

This example is a lot of a mess, and there are other ways to achieve much of this in html_document2 outputs.

The key thing with flexdashboards, as it is setup in this file:

  1. Level 1 headings (marked by \===== ) define a new page
  2. Level 2 headings (marked by \---- ) define another section type. This might be a set of panes, or if you have \{.tabset\} the start of a section you want to appear in tabs
  3. Level 3 headings (marked by \###) define the actual sections that appear

Column {data-width 200}

Setting up and finding out more about Flex

The valueBox outputs below are not displaying as desired, someone might want to explore how to use these more effectively.

Column {data-width 400}

Group mean daily steps

Days below recommendation

comment

I am not adept at using the Flexdashboard system. But, you can see it’s relatively easy to create interactives.

You can also include some fun things in flexdashboards that aren’t by default in other outputs. For example, value boxes:

Using the template

In the other pages I’ll show one way to setup a flexdashboard to use for the template. There are lots of variations and you will need to explore.

Introduction

Introduction

Introduction

a paragraph that gives an overview of what you’ve done

Description of process, or method

this is where you give details about what you’ve been collecting and how much you data have; why you choose this data to collect; how you managed the quality and frequency of collection issues; what you did to anonymise or de-identify the data, and how you dealt with the storage and sharing of data within the group. Do not include a dump of all your data here. If you wish to include examples of data (and I think you should) then put these in an appendix to the report.
Criterion 1: Justifies a method to obtain data from multiple sources, for gaining insight into a chosen problem, including analysis of data quality issues in the individual and group data.

Data collected {data-width 400}

Datasets

Data Frame Summary

starwars

Dimensions: 87 x 8
Duplicates: 0
Variable Stats / Values Freqs (% of Valid) Graph Missing
name [character]
1. Ackbar
2. Adi Gallia
3. Anakin Skywalker
4. Arvel Crynyd
5. Ayla Secura
6. Bail Prestor Organa
7. Barriss Offee
8. BB8
9. Ben Quadinaros
10. Beru Whitesun lars
[ 77 others ]
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
1(1.1%)
77(88.5%)
0 (0.0%)
height [integer]
Mean (sd) : 174.4 (34.8)
min ≤ med ≤ max:
66 ≤ 180 ≤ 264
IQR (CV) : 24 (0.2)
45 distinct values 6 (6.9%)
mass [numeric]
Mean (sd) : 97.3 (169.5)
min ≤ med ≤ max:
15 ≤ 79 ≤ 1358
IQR (CV) : 28.9 (1.7)
38 distinct values 28 (32.2%)
hair_color [character]
1. none
2. brown
3. black
4. white
5. blond
6. auburn
7. auburn, grey
8. auburn, white
9. blonde
10. brown, grey
[ 2 others ]
37(45.1%)
18(22.0%)
13(15.9%)
4(4.9%)
3(3.7%)
1(1.2%)
1(1.2%)
1(1.2%)
1(1.2%)
1(1.2%)
2(2.4%)
5 (5.7%)
skin_color [character]
1. fair
2. light
3. dark
4. green
5. grey
6. pale
7. brown
8. blue
9. blue, grey
10. orange
[ 21 others ]
17(19.5%)
11(12.6%)
6(6.9%)
6(6.9%)
6(6.9%)
5(5.7%)
4(4.6%)
2(2.3%)
2(2.3%)
2(2.3%)
26(29.9%)
0 (0.0%)
birth_year [numeric]
Mean (sd) : 87.6 (154.7)
min ≤ med ≤ max:
8 ≤ 52 ≤ 896
IQR (CV) : 37 (1.8)
36 distinct values 44 (50.6%)
homeworld [character]
1. Naboo
2. Tatooine
3. Alderaan
4. Coruscant
5. Kamino
6. Corellia
7. Kashyyyk
8. Mirial
9. Ryloth
10. Aleen Minor
[ 38 others ]
11(14.3%)
10(13.0%)
3(3.9%)
3(3.9%)
3(3.9%)
2(2.6%)
2(2.6%)
2(2.6%)
2(2.6%)
1(1.3%)
38(49.4%)
10 (11.5%)
species [character]
1. Human
2. Droid
3. Gungan
4. Kaminoan
5. Mirialan
6. Twi'lek
7. Wookiee
8. Zabrak
9. Aleena
10. Besalisk
[ 27 others ]
35(42.2%)
6(7.2%)
3(3.6%)
2(2.4%)
2(2.4%)
2(2.4%)
2(2.4%)
2(2.4%)
1(1.2%)
1(1.2%)
27(32.5%)
4 (4.6%)

Generated by summarytools 1.0.0 (R version 4.1.2)
2022-01-14

Analysis

Analysis

Analysis introduction

describe how you analysed your data, and how you contrasted your data with the group’s data.
Criterion 2: Justifies the analysis of the obtained data, including quality issues, to draw conclusions in a professional and engaging manner.

Get and load data

Please don’t show me all the processing code, just highlight - in text - any key issues in working with the data (and you can call scripts in collapsed code chunks if you want).

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa
5.4 3.7 1.5 0.2 setosa
4.8 3.4 1.6 0.2 setosa
4.8 3.0 1.4 0.1 setosa
4.3 3.0 1.1 0.1 setosa
5.8 4.0 1.2 0.2 setosa
5.7 4.4 1.5 0.4 setosa
5.4 3.9 1.3 0.4 setosa
5.1 3.5 1.4 0.3 setosa
5.7 3.8 1.7 0.3 setosa
5.1 3.8 1.5 0.3 setosa
5.4 3.4 1.7 0.2 setosa
5.1 3.7 1.5 0.4 setosa
4.6 3.6 1.0 0.2 setosa
5.1 3.3 1.7 0.5 setosa
4.8 3.4 1.9 0.2 setosa
5.0 3.0 1.6 0.2 setosa
5.0 3.4 1.6 0.4 setosa
5.2 3.5 1.5 0.2 setosa
5.2 3.4 1.4 0.2 setosa
4.7 3.2 1.6 0.2 setosa
4.8 3.1 1.6 0.2 setosa
5.4 3.4 1.5 0.4 setosa
5.2 4.1 1.5 0.1 setosa
5.5 4.2 1.4 0.2 setosa
4.9 3.1 1.5 0.2 setosa
5.0 3.2 1.2 0.2 setosa
5.5 3.5 1.3 0.2 setosa
4.9 3.6 1.4 0.1 setosa
4.4 3.0 1.3 0.2 setosa
5.1 3.4 1.5 0.2 setosa
5.0 3.5 1.3 0.3 setosa
4.5 2.3 1.3 0.3 setosa
4.4 3.2 1.3 0.2 setosa
5.0 3.5 1.6 0.6 setosa
5.1 3.8 1.9 0.4 setosa
4.8 3.0 1.4 0.3 setosa
5.1 3.8 1.6 0.2 setosa
4.6 3.2 1.4 0.2 setosa
5.3 3.7 1.5 0.2 setosa
5.0 3.3 1.4 0.2 setosa
7.0 3.2 4.7 1.4 versicolor
6.4 3.2 4.5 1.5 versicolor
6.9 3.1 4.9 1.5 versicolor
5.5 2.3 4.0 1.3 versicolor
6.5 2.8 4.6 1.5 versicolor
5.7 2.8 4.5 1.3 versicolor
6.3 3.3 4.7 1.6 versicolor
4.9 2.4 3.3 1.0 versicolor
6.6 2.9 4.6 1.3 versicolor
5.2 2.7 3.9 1.4 versicolor
5.0 2.0 3.5 1.0 versicolor
5.9 3.0 4.2 1.5 versicolor
6.0 2.2 4.0 1.0 versicolor
6.1 2.9 4.7 1.4 versicolor
5.6 2.9 3.6 1.3 versicolor
6.7 3.1 4.4 1.4 versicolor
5.6 3.0 4.5 1.5 versicolor
5.8 2.7 4.1 1.0 versicolor
6.2 2.2 4.5 1.5 versicolor
5.6 2.5 3.9 1.1 versicolor
5.9 3.2 4.8 1.8 versicolor
6.1 2.8 4.0 1.3 versicolor
6.3 2.5 4.9 1.5 versicolor
6.1 2.8 4.7 1.2 versicolor
6.4 2.9 4.3 1.3 versicolor
6.6 3.0 4.4 1.4 versicolor
6.8 2.8 4.8 1.4 versicolor
6.7 3.0 5.0 1.7 versicolor
6.0 2.9 4.5 1.5 versicolor
5.7 2.6 3.5 1.0 versicolor
5.5 2.4 3.8 1.1 versicolor
5.5 2.4 3.7 1.0 versicolor
5.8 2.7 3.9 1.2 versicolor
6.0 2.7 5.1 1.6 versicolor
5.4 3.0 4.5 1.5 versicolor
6.0 3.4 4.5 1.6 versicolor
6.7 3.1 4.7 1.5 versicolor
6.3 2.3 4.4 1.3 versicolor
5.6 3.0 4.1 1.3 versicolor
5.5 2.5 4.0 1.3 versicolor
5.5 2.6 4.4 1.2 versicolor
6.1 3.0 4.6 1.4 versicolor
5.8 2.6 4.0 1.2 versicolor
5.0 2.3 3.3 1.0 versicolor
5.6 2.7 4.2 1.3 versicolor
5.7 3.0 4.2 1.2 versicolor
5.7 2.9 4.2 1.3 versicolor
6.2 2.9 4.3 1.3 versicolor
5.1 2.5 3.0 1.1 versicolor
5.7 2.8 4.1 1.3 versicolor
6.3 3.3 6.0 2.5 virginica
5.8 2.7 5.1 1.9 virginica
7.1 3.0 5.9 2.1 virginica
6.3 2.9 5.6 1.8 virginica
6.5 3.0 5.8 2.2 virginica
7.6 3.0 6.6 2.1 virginica
4.9 2.5 4.5 1.7 virginica
7.3 2.9 6.3 1.8 virginica
6.7 2.5 5.8 1.8 virginica
7.2 3.6 6.1 2.5 virginica
6.5 3.2 5.1 2.0 virginica
6.4 2.7 5.3 1.9 virginica
6.8 3.0 5.5 2.1 virginica
5.7 2.5 5.0 2.0 virginica
5.8 2.8 5.1 2.4 virginica
6.4 3.2 5.3 2.3 virginica
6.5 3.0 5.5 1.8 virginica
7.7 3.8 6.7 2.2 virginica
7.7 2.6 6.9 2.3 virginica
6.0 2.2 5.0 1.5 virginica
6.9 3.2 5.7 2.3 virginica
5.6 2.8 4.9 2.0 virginica
7.7 2.8 6.7 2.0 virginica
6.3 2.7 4.9 1.8 virginica
6.7 3.3 5.7 2.1 virginica
7.2 3.2 6.0 1.8 virginica
6.2 2.8 4.8 1.8 virginica
6.1 3.0 4.9 1.8 virginica
6.4 2.8 5.6 2.1 virginica
7.2 3.0 5.8 1.6 virginica
7.4 2.8 6.1 1.9 virginica
7.9 3.8 6.4 2.0 virginica
6.4 2.8 5.6 2.2 virginica
6.3 2.8 5.1 1.5 virginica
6.1 2.6 5.6 1.4 virginica
7.7 3.0 6.1 2.3 virginica
6.3 3.4 5.6 2.4 virginica
6.4 3.1 5.5 1.8 virginica
6.0 3.0 4.8 1.8 virginica
6.9 3.1 5.4 2.1 virginica
6.7 3.1 5.6 2.4 virginica
6.9 3.1 5.1 2.3 virginica
5.8 2.7 5.1 1.9 virginica
6.8 3.2 5.9 2.3 virginica
6.7 3.3 5.7 2.5 virginica
6.7 3.0 5.2 2.3 virginica
6.3 2.5 5.0 1.9 virginica
6.5 3.0 5.2 2.0 virginica
6.2 3.4 5.4 2.3 virginica
5.9 3.0 5.1 1.8 virginica

Tables

#knitr::kable(summary(iris))
knitr::kable(describe(iris))
vars n mean sd median trimmed mad min max range skew kurtosis se
Sepal.Length 1 150 5.843333 0.8280661 5.80 5.808333 1.03782 4.3 7.9 3.6 0.3086407 -0.6058125 0.0676113
Sepal.Width 2 150 3.057333 0.4358663 3.00 3.043333 0.44478 2.0 4.4 2.4 0.3126147 0.1387047 0.0355883
Petal.Length 3 150 3.758000 1.7652982 4.35 3.760000 1.85325 1.0 6.9 5.9 -0.2694109 -1.4168574 0.1441360
Petal.Width 4 150 1.199333 0.7622377 1.30 1.184167 1.03782 0.1 2.5 2.4 -0.1009166 -1.3581792 0.0622364
Species* 5 150 2.000000 0.8192319 2.00 2.000000 1.48260 1.0 3.0 2.0 0.0000000 -1.5199333 0.0668900

You’ll see above that I used a labelled for the table, I did that by adding \@ref(tab:summarise_data). Now, I can use this to refer to it like this \@ref(tab:summarise_data).

Exploring step data

Let’s have a look at two ways visualisations together.

p1 <- ggplot(iris, aes = Sepal.Length, fill = Species) + 
  geom_boxplot()

p2 <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) + geom_histogram(alpha = .5, position = 'identity') 

gridExtra::grid.arrange(p2, p2, nrow = 1) #should also work 
histograms

histograms

#shiny::splitLayout(cellWidths=c("50%"), p1, p2) #may work

The ggplot package makes nicer figures than base R, like that shown in figr("pretty_histograms", type = "Figure"). Packages like gridExtra let us lay out multiple plots, and text effectively.

Discussion

Discussion, etc.

Findings and Conclusions

<what conclusions did you come to as a result of the analysis of your data and of the group’s data.
Criterion 2: Justifies the analysis of the obtained data, including quality issues, to draw conclusions in a professional and engaging manner.>

Discussion

discuss aspects of the process that you see as important. For example, what difficulties did you encounter; how could you avoid problems if you did it again; etc>

Your ‘justification’ and evaluation of your approach is likely to go in this section, but may also be threaded through the preceding sections. This includes Criterion 3: Identifies, contextualises, and reflects on the ethical, privacy, and legal issues relevant to the collection and analysis of personal data of self and others. >

Reflection

<General reflection on what you learnt during this task. What are you unsure about? What would you do differently if you had to do it all again?
Criteria 4: Connects the individual experience of this QS project to the practice of data science (and the preceding three criteria). >

References

References

Your reference list should go here

---
title: "The Quantified Self"
author: "Simon Knight"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    #storyboard: true
    vertical_layout: scroll
    social: menu
    source_code: embed
    theme:
      version: 4

---


```{r setup-flex, include=FALSE, message=FALSE}
library(flexdashboard)
library(tidyverse)
library(psych)

#The folowing probably aren't needed, check
#library(reshape2)
#library(plotly)
# library(ggthemes)
# library(GGally)
# library(gridExtra)
#library(chron) workshandles data and times

#There's also a few lines to modify the CSS below to put the navigation on the side (rather than at the top) of the dashboard. Remove it to revert to the default.

#I've also loaded a theme (flatly) - you can define your own.  Let's set the the rmd theme to match

thematic::thematic_rmd()
```

Preamble
=====================================     

Column {data-width 400}
-------------------------------------

### Flexdashboard Template for DSI AT2

```{r}
plot(mtcars$mpg)
```

I'm not sure a flexdashboard is a great way to present this kind of work, because it's a lot of text, while dashboards are really built for bits of commentary but mostly visual information.

This example is a lot of a mess, and there are other ways to achieve much of this in html_document2 outputs. 

The key thing with flexdashboards, as it is setup in this file:

1. Level 1 headings (marked by `\===== )` define a new page
1. Level 2 headings (marked by `\---- )` define another section type. This might be a set of panes, or if you have `\{.tabset\}` the start of a section you want to appear in tabs
1. Level 3 headings (marked by `\###)` define the actual sections that appear


Column {data-width 200}
-------------------------------------
   
### Setting up and finding out more about Flex
The valueBox outputs below are not displaying as desired, someone might want to explore how to use these more effectively.

Column {data-width 400}
---------------------

### Group mean daily steps

`r flexdashboard::valueBoxOutput(flexdashboard::valueBox(5430, caption = "Group mean", icon = "fa-pencil"), width = "30%")`

### Recommended steps

```{r}

flexdashboard::valueBoxOutput(flexdashboard::valueBox(10000, caption="Recommended", icon = "fa-stethoscope"), width = "30%")

```

### Days below recommendation

```{r}
n <- 70
flexdashboard::valueBoxOutput(flexdashboard::valueBox(n, 
         caption = "% below", 
         icon = "fa-pencil",
         color = ifelse(n > 50, "warning", "primary")),
         width = "30%") 

#colour conditional if over 50% 
```

### comment

I am not adept at using the Flexdashboard system. But, you can see it's relatively easy to create interactives.

You can also include some fun things in flexdashboards that aren't by default in other outputs. For example, value boxes: 


### Using the template

In the other pages I'll show one way to setup a flexdashboard to use for the template. There are lots of variations and you will need to explore. 


Introduction
=================================

Introduction
---------------------------------------

### Introduction

a paragraph that gives an overview of what you’ve done

### Description of process, or method

this is where you give details about what you’ve been collecting and how much you data have; why you choose this data to collect; how you managed the quality and frequency of collection issues; what you did to anonymise or de-identify the data, and how you dealt with the storage and sharing of data within the group. Do not include a dump of all your data here. If you wish to include examples of data (and I think you should) then put these in an appendix to the report.  
Criterion 1: Justifies a method to obtain data from multiple sources, for gaining insight into a chosen problem, including analysis of data quality issues in the individual and group data.

Data collected {data-width 400}
---------------------------------------

### Datasets

```{r}
#skimr::skim()
#summarytools::stview
library(dplyr)
starwars %>% select(
  name, height, mass, hair_color, skin_color, birth_year, homeworld, species) %>% 
  summarytools::dfSummary(.,
                          max.distinct.values=10,
                          plain.ascii = FALSE,
                          style = 'grid',
                          graph.magnif = 0.85,
                          varnumbers = FALSE,
                          valid.col = FALSE,
                          tmp.img.dir = "/tmp") %>%
  print(method='render')

```


Analysis
=====================================   

Analysis {.tabset}
---------------------------------------

### Analysis introduction {.tabset}

describe how you analysed your data, and how you contrasted your data with the group’s data.   
Criterion 2: Justifies the analysis of the obtained data, including quality issues, to draw conclusions in a professional and engaging manner.

### Get and load data {.tabset}

Please don't show me all the processing code, just highlight - in text - any key issues in working with the data (and you can call scripts in collapsed code chunks if you want).

```{r getting_data_flex, echo=FALSE, message=FALSE, warning=FALSE, paged.print=TRUE}
#We're just going to demo this with one of the built in datasets
df <- data(iris)

#And 
knitr::kable(iris)
```

### Tables {.tabset}

```{r summarise_data, tab.cap="A summary table", echo=T}
#knitr::kable(summary(iris))
knitr::kable(describe(iris))

```

You'll see above that I used a labelled for the table, I did that by adding `\@ref(tab:summarise_data)`. Now, I can use this to refer to it like this \\@ref(tab:summarise_data). 

### Exploring step data {.tabset}

Let's have a look at two ways visualisations together. 

```{r histograms, echo=TRUE, echo=TRUE, anchor = "Figure", fig.cap="histograms", fig.width=4, fig.height=4}

p1 <- ggplot(iris, aes = Sepal.Length, fill = Species) + 
  geom_boxplot()

p2 <- ggplot(iris, aes(x = Sepal.Length, fill = Species)) + geom_histogram(alpha = .5, position = 'identity') 

gridExtra::grid.arrange(p2, p2, nrow = 1) #should also work 
#shiny::splitLayout(cellWidths=c("50%"), p1, p2) #may work

```

The ggplot package makes nicer figures than base `R`, like that shown in `figr("pretty_histograms", type = "Figure")`. Packages like gridExtra let us lay out multiple plots, and text effectively. 

Discussion
=====================================   

Discussion, etc.
--------------------------------

### Findings and Conclusions

\

### Discussion

discuss aspects of the process that you see as important. For example, what difficulties did you encounter;  how could you avoid problems if you did it again; etc>

Your ‘justification’ and evaluation of your approach is likely to go in this section, but may also be threaded through the preceding sections. This includes Criterion 3: Identifies, contextualises, and reflects on the ethical, privacy, and legal issues relevant to the collection and analysis of personal data of self and others. \> 

### Reflection

\ 

References {data-orientation=rows}
=====================================   

### References {#flex_refs}

Your reference list should go here